﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;


using MusicPlayerLib.Utils;
using MusicPlayerLib.DataModel;
using P2PLib.Client.DataModel;
using P2PLib.Client.ViewModel;
using P2PLib.Client.Utils;
using P2PLib.Common.DataModel;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {

            //DirectoryInfo[] dirs = new DirectoryInfo[1];
            //dirs[0] = new DirectoryInfo(@"E:\Music");

            //MediaLibrary library = MusicPlayerUtils.GenerateMediaLibrary(dirs);

            //XmlSerializer xs = new XmlSerializer(typeof(MediaLibrary));

            //FileStream fs = new FileStream(@"E:\music\library.xml", FileMode.OpenOrCreate);
            //xs.Serialize(fs, library);

            //List<AudioFile> afs = MusicPlayerUtils.GetAudioFiles(dirs[0]);

            //Playlist pl = new Playlist("default");
            //pl.Tracks = afs;

            //PlaylistUtils.SavePlaylist(@"E:\", pl);

            //DirectoryInfo[] dirs = new DirectoryInfo(@"E:\Music\April\Adele.-.[19.(Limited.Edition)].专辑.(MP3)").GetDirectories();

            //SharedFileLibrary fl = SharedFileLibraryUtils.GenerateFileList(dirs);

            //Console.WriteLine(fl.Files.Count);

            //SharedFileLibraryUtils.SaveFileList(@"E:\", fl);

            //DownloadTastUtilsTest();

           // SearchLibraryTest();

            Console.Read();
        }


        public static void DownloadTastUtilsTest()
        {
            CFileInfo cf = new CFileInfo();
            cf.FileName = "星球大战.avi";
            cf.FileSize = 293839;
            cf.FileHashCode = "3938928929934823392029";

            Random random = new Random();

            DownloadTaskList list = new DownloadTaskList();

            for (int i = 0; i < 10; i++)
            {
                DownloadTask t = new DownloadTask();
                t.File = cf;
                t.CompletedSize = random.Next((int)cf.FileSize);
                
                t.StartedTime = DateTime.Now;
                list.Tasks.Add(t);
            }

            DownloadTaskUtils.SaveDownloadTasks(list, @"E:\");
        }


        //public static void SearchLibraryTest()
        //{
        //    DirectoryInfo[] dirs = new DirectoryInfo(@"F:\学习资料\WPF").GetDirectories();

        //    SharedFileLibrary sfl = 
        //        SharedFileLibraryUtils.GenerateFileList(dirs);
        //    //SharedFileLibraryUtils.SaveFileList(@"F:\Programming\Visual Studio 2008\NewPanda\NewPanda\bin\Debug\sharedFiles.xml",sfl);

        //    //SharedFileLibrary sfl = SharedFileLibraryUtils.LoadSharedFileLibrary(@"F:\Programming\Visual Studio 2008\NewPanda\NewPanda\bin\Debug\sharedFiles.xml");
        //    List<CFileInfo> result = ClientUtils.SearchLibrary(sfl, "WPf",P2PLib.Client.Command.SearchType.ByKeyWord);

        //    foreach (CFileInfo f in result)
        //    {
        //        Console.WriteLine("{0}", f.FileName);
        //    }

        //    ClientInfo client = new ClientInfo("127.0.0.1", 2222);

        //    SearchResultListViewModel srlvm = new SearchResultListViewModel();

        //    srlvm.AddResult(result, client);

        //    foreach (SearchResultViewModel srvm in srlvm.ResultList)
        //    {
        //        Console.WriteLine("Title:{0}, Soruce:{1}", srvm.File.FileName, srvm.SourceCount);
        //    }
        //}
    }
}
